package org.example;

public class Test1 {
    //leetcode 环形链表
    //https://leetcode.cn/problems/linked-list-cycle/description/?envType=problem-list-v2&envId=hash-table
    public boolean hasCycle(ListNode head) {
        if (head == null) return false;
        ListNode slow = head,fast = head.next;
        while (slow != null && fast != null) {
            slow = slow.next;
            fast = fast.next != null ? fast.next.next : null;
            if (slow == fast) return true;
        }
        return false;
    }
}
